local Lua__tongku = fk.CreateSkill {

  name = "Lua__tongku",

  tags = { Skill.Compulsory, },

}

Fk:loadTranslationTable{
    ["Lua__tongku"] = "痛哭",
    ["$Lua__tongku1"] = "我扛不住了我扛不住了😭",
    ["$Lua__tongku2"] = "操！操！操！😡",
    [":Lua__tongku"] = "锁定技。若你的体力值不大于2，你始终背面朝上且受到的伤害-2。否则你始终正面朝上且造成的伤害+1。",
}

Lua__tongku:addEffect(fk.HpChanged, {
    anim_type = "control",
    mute = true,
    can_trigger = function (self, event, target, player, data)
      local room = player.room
      if player:hasSkill(Lua__tongku.name) and target and target == player then
        if player.hp <= 2 and player.faceup then
          player:broadcastSkillInvoke("Lua__tongku", 1)
          return true
        elseif player.hp > 2 and not player.faceup then
          player:broadcastSkillInvoke("Lua__tongku", 2)
          return true
        end
      end
    end,
    on_use = function (self, event, target, player, data)
      player:turnOver()
    end,
})
Lua__tongku:addEffect(fk.BeforeTurnOver, {
    anim_type = "control",
    mute = true,
    can_trigger = function (self, event, target, player, data)
      local room = player.room
      if player:hasSkill(Lua__tongku.name) and target and target == player then
        local e = room.logic:getCurrentEvent():findParent(GameEvent.SkillEffect)
        if not(e and e.data == self) then
          if player.hp <= 2 and not player.faceup then
            return true
          elseif player.hp > 2 and player.faceup then
            return true
          end
        end
      end
    end,
    on_use = function (self, event, target, player, data)
      data.prevented = true
    end,
})

Lua__tongku:addEffect(fk.DamageInflicted, {
    can_refresh = function (self, event, target, player, data)
      if player:hasSkill(Lua__tongku.name) and target and target == player then
        if event == fk.DamageInflicted then
          return not player.faceup
        else
          return player.faceup  
        end
      end
    end,
    on_refresh = function (self, event, target, player, data)
      player.room:notifySkillInvoked(player,Lua__tongku.name)
      if event == fk.DamageInflicted then
        data.damage = data.damage - 2
      else
        data.damage = data.damage + 1
      end
    end,
})
Lua__tongku:addEffect(fk.DamageCaused, {
    can_refresh = function (self, event, target, player, data)
      if player:hasSkill(Lua__tongku.name) and target and target == player then
        if event == fk.DamageInflicted then
          return not player.faceup
        else
          return player.faceup  
        end
      end
    end,
    on_refresh = function (self, event, target, player, data)
      player.room:notifySkillInvoked(player,Lua__tongku.name)
      if event == fk.DamageInflicted then
        data.damage = data.damage - 2
      else
        data.damage = data.damage + 1
      end
    end,
})

Lua__tongku:addAcquireEffect(function(self, player)
    if player.hp <= 2 and player.faceup then
      player:turnOver()
    elseif player.hp > 2 and not player.faceup then
      player:turnOver()
    end
end)

return Lua__tongku